package com.wclass.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.wclass.entity.BaseAppUser;
import com.wclass.entity.BaseFocus;
import com.wclass.mapper.BaseFocusMapper;
import com.wclass.service.IBaseFocusService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 关注表 服务实现类
 * </p>
 *
 * @author 张浩高
 * @since 2018-12-21
 */
@Service
public class BaseFocusServiceImpl extends ServiceImpl<BaseFocusMapper, BaseFocus> implements IBaseFocusService {


    @Override
    public boolean insert(BaseFocus entity) {
        boolean bool = super.insert(entity);
        baseMapper.StatFanNum(entity.getFocusUserId());
        baseMapper.StatFocusNum(entity.getUserId());
        return bool;
    }

    @Override
    public boolean delete(Wrapper<BaseFocus> wrapper) {
        List<BaseFocus> BaseFocus = baseMapper.selectList(wrapper);
        boolean bool = super.delete(wrapper);
        if (BaseFocus.size() > 0) {
            baseMapper.StatFanNum(BaseFocus.get(0).getFocusUserId());
            baseMapper.StatFocusNum(BaseFocus.get(0).getUserId());
        }
        return bool;
    }

    @Override
    public List<BaseAppUser> selectFansList(EntityWrapper<BaseFocus> ew) {
        return baseMapper.selectFansList(ew);
    }
}
